package pro.spring.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import pro.spring.inter.UsersMapper;
import pro.spring.model.Users;
import pro.spring.vo.PaginationVo;

@Service
public class UsersService{

	@Autowired
	private UsersMapper UsersMapper;
	
	public int deleteByPrimaryKey(Integer id) {
		return UsersMapper.deleteByPrimaryKey(id);
	}

	public int insert(Users record) {
		return UsersMapper.insert(record);
	}
	
	public Users selectByEmail(String email) {
		return UsersMapper.selectByEmail(email);
	}
	
	public Integer selectByAccount(String account) {
		return UsersMapper.selectByAccount(account);
	}
	
	public int selectName(String name) {
		return UsersMapper.selectName(name);
	}

	public Users selectByPrimaryKey(Integer id) {
		return UsersMapper.selectByPrimaryKey(id);
	}

	public int updateByPrimaryKey(Users record) {
		return UsersMapper.updateByPrimaryKey(record);
	}
	
	public Users selectLogin(String name ,String pass) {
		return UsersMapper.selectLogin(name, pass);
	}
	
	public PaginationVo<Users> getPaginationInfo(int pagenum,int pagesize){
		//int pagenum是当前的页码,int pagesize是每页显示的数据数量
		PaginationVo<Users> pageVo=new PaginationVo<Users>();
		//一定要在setPageCount()方法之后执行setPageNum
		pageVo.setCount(UsersMapper.selectCount());
		pageVo.setRows(pagesize);
		pageVo.setPageNum(pagenum);
		pageVo.setList(UsersMapper.selectListPage(pageVo.getOffset(), pageVo.getRows()));
		return pageVo;
	}
}
